package homework03;

/**
 * @Description: TODO
 * @author: shenbing.wang@hand-china
 * @date: 2021年06月09日 15:18
 */

/**
 * 用户消费类
 * 1、统计通话时长
 * 2、统计上网流量
 * 3、每月消费金额
 */
public class Code0203Consumption {
    private int callTime;
    private int internetTraffic;
    private int expenses;

    /**
     * callTime            统计通话时长
     * internetTraffic     统计上网流量
     * expenses            统计消费金额
     */

    Code0203Consumption() {
    }

    public Code0203Consumption(int callTime, int internetTraffic, int expenses) {
        setCallTime(callTime);
        setInternetTraffic(internetTraffic);
        setExpenses(expenses);
    }

    public int getCallTime() {
        return callTime;
    }

    public void setCallTime(int callTime) {
        this.callTime = callTime;
    }

    public int getInternetTraffic() {
        return internetTraffic;
    }

    public void setInternetTraffic(int internetTraffic) {
        this.internetTraffic = internetTraffic;
    }

    public int getExpenses() {
        return expenses;
    }

    public void setExpenses(int expenses) {
        this.expenses = expenses;
    }
// 　　通话时长方法与统计上网流量方法只能依顺序进行，确保账户扣款的准确性
// 　　1、接收到普通通话类传过来的参数，根据手机卡情况统计消费时长并且打印账户余额，如果账户中通话时长为0就是初始通话调用if中的语句，如果账户中通话时长大于0就是历史通话调用else语句

    public void countCallTime(int quantity, int expenses, Code0203PhoneCard code0203PhoneCard) {
        //  统计通话时长
        if (code0203PhoneCard.getCallTime() == 0) {
            code0203PhoneCard.setCallTime(quantity);    //  初次通话时间
        } else {
            setCallTime(code0203PhoneCard.getCallTime() + quantity);
            code0203PhoneCard.setCallTime(getCallTime());   //  登记历史通话时间
        }
        code0203PhoneCard.setAccountBalance(code0203PhoneCard.getAccountBalance() - (quantity * expenses));
        System.out.println("============================历史通话时间==================================");
        System.out.printf("历史通话时间：%d分钟，账户余额%d元\n", code0203PhoneCard.getCallTime(), code0203PhoneCard.getAccountBalance());
    }
//　　2、接收普通上网类传过来的参数，根据手机卡情况统计上网情况，原理与上述方法一致

    public void countInternetTraffic(int quantity, int expenses, Code0203PhoneCard code0203PhoneCard) {
        //  统计上网流量
        if (code0203PhoneCard.getInternetTraffic() == 0) {
            code0203PhoneCard.setInternetTraffic(quantity);    //初次登记历史通话时间
        } else {
            setInternetTraffic(code0203PhoneCard.getInternetTraffic() + quantity);
            code0203PhoneCard.setInternetTraffic(getInternetTraffic());
        }
        code0203PhoneCard.setAccountBalance(code0203PhoneCard.getAccountBalance() - (quantity * expenses));
        System.out.println("==========================历史流量使用情况================================");
        System.out.printf("历史流量使用情况：%dGB,账户余额%d元\n", code0203PhoneCard.getInternetTraffic(), code0203PhoneCard.getAccountBalance());
    }

}
